#include<bits/stdc++.h>
using namespace std;
using ll = long long;
//#define a cout<<"A"<<endl
//#define b cout<<"B"<<endl
void solve()
{
	ll a, b;
	cin >> a >> b;
	ll sa = 0, sb = 0;
	string na, nb;
	na = to_string(a), nb = to_string(b);
	for (int i = 0; i < na.size();i++)
	{
		sa += na[i] - '0';
	}
	for (int i = 0; i < nb.size();i++)
	{
		sb += nb[i] - '0';
	}
	//if(a%sb==0&&b%sa==0)
	//{
	//  cout <<( a > b ? "A" : "B" )<< endl;
	//}
	if (a % sb == 0&&b%sa!=0)
	{
		cout << "A" << endl;
	}
	else if(b%sa==0&&a&sb!=0)
		cout << "B" << endl;
	else cout<<(a>b?'A':'B')<<endl;
}
int main()
{
	int n;
	cin >> n;
	while(n--)
	{
		solve();
	}
	return 0;
}
